package javamusic.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javamusic.excepcion.DAOExcepcion;
import javamusic.modelo.Comprobante;
import javamusic.util.ConexionBDKaraoke;

public class ComprobanteDAO extends BaseDAO{

	public Collection<Comprobante> buscarIdComprobante(int idcomprobante) throws DAOExcepcion {
		String query = "select idcomprobante, fecha, monto, idcajero from comprobante where idcomprobante like ?";
		Collection<Comprobante> lista = new ArrayList<Comprobante>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBDKaraoke.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1, "%" + idcomprobante + "%");
			rs = stmt.executeQuery();
			while (rs.next()) {
				Comprobante vo = new Comprobante();
				vo.setIdcomprobante(rs.getInt("idcomprobante"));
				vo.setFecha(rs.getString("fecha"));
				vo.setMonto(rs.getDouble("monto"));
				vo.setIdcajero(rs.getInt("idcajero"));
				lista.add(vo);
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
						
		return lista;
	}
	
}
